﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;

namespace Sinacor.Deployment.Setup.Wizard.Steps
{
    public class Introduction : BaseStep
    {
        public StepNavigationAction NavigationAction { get; protected set; }
        UI.Introduction introduction = null;

        public Introduction(IStepGroup parent)
            :base(parent)
        {
            this.Id = "Introduction";
            this.ExecutionFinished += new EventHandler<PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs>(Introduction_ExecutionFinished);
            this.ErrorBehavior = StepErrorBehavior.NotifyParent;
            this.NavigationBehavior = StepNavigationBehavior.NextCancel;
        }

        void Introduction_ExecutionFinished(object sender, PSE.Deployment.Engine.CustomEventArgs.ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            introduction = new UI.Introduction();
            introduction.ShowDialog();

            this.NavigationAction = introduction.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (introduction != null)
                introduction.Close(false);
        }
    }
}
